package com.gogowan.agroenterprise.utils;

import android.os.CountDownTimer;

/*原生倒计时工具类*/

public class CountDownTimerUtil extends CountDownTimer {
    private OnCountdownListener listener;
    private static CountDownTimerUtil util;
    public CountDownTimerUtil(long timelength, OnCountdownListener listener) {
        super(timelength*1000, 1000);
        this.listener=listener;
    }
    public static void init(long timelength,OnCountdownListener listener){
        util=new CountDownTimerUtil(timelength,listener);
        util.start();
    }
    @Override
    public void onTick(long l) {
        if (listener!=null){
            listener.seconds(l/1000);
        }
    }

    @Override
    public void onFinish() {
        if (listener!=null){
            listener.complete();
        }
    }
    public interface  OnCountdownListener{
        void seconds(long second);
        void complete();
    }
}
